<template>
    <div>
        <div style="width: 200px;height: 50px;border: solid black 1px">
            <h1>在线人数：{{len}}</h1>
        </div>
    </div>
</template>

<script>
export default {
    name: "loglen",
    data(){
        return{
            len: '',
            socket: ''
        }
    },
    methods:{
        showModal() {
            this.socket = new WebSocket(`ws:192.168.1.221:8000/loginlen/`)
            this.socket.onopen = function (e){
                console.log('连接成功')
            }
            this.socket.onmessage = this.websocketonmessage
        },
        websocketonmessage(e){
            let dataJson = JSON.parse(e.data)
            this.len = dataJson.len
        }
    }
    ,
    mounted() {
        this.showModal()
    }
}
</script>

<style scoped>

</style>
